//
//  ControllerViewController.m
//  微博2期
//
//  Created by J on 15/12/6.
//
//

#import "ComposeViewController.h"
#import "AccountTool.h"
#import "PlaceHolderTextView.h"
@interface ComposeViewController ()
@property(nonatomic,weak) PlaceHolderTextView * textView;
@end

@implementation ComposeViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.view.backgroundColor =[UIColor whiteColor];
    
//    self.automaticallyAdjustsScrollViewInsets = NO;//自动调增scrollViewInset 当scrollView 遇到NavigationBar UITabBar ToolBar Tabbar的情况下 不论是否被导航栏挡住 都会内缩63
    [self setupNav];//设置导航栏内容
    
    [self setupTextView];//添加输入控件
}

/**
 UITextField
 1.文字永远是一行, 不能显示多行文字
 2.有placeholder属性设置占位文字
 3.继承于UIControl  可以通过 - (void)addTarget:(nullable id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents; 监听
 4.监听一些行为
 1>设置代理
 2>addTarget:action:forEvent:
 3>通知  UITextFieldTextDidEndEditingNotification
 
 UITextView:
 1.能显示任意行文字
 2.不能设置占位文字
 3.继承于 UIScrollView 内容超出了可以滚动
 4.设置代理
 5.通知 UITextViewTextDidEndEditingNotification
 
 */


- (UITextView *)textView{
    
    if (!_textView) {
        
        PlaceHolderTextView * textView = [[PlaceHolderTextView alloc]init];
        textView.placeHolder = @"分享你的新鲜事...";
        textView.placeholderColor = [UIColor grayColor];
//        textView.height = 150;
//        textView.backgroundColor = [UIColor purpleColor];
        textView.frame = self.view.bounds;
//        textView.y = 64;
        textView.font = [UIFont systemFontOfSize:15];
//        NSLog(@"%zd",self.automaticallyAdjustsScrollViewInsets);
        self.textView = textView;//{64, 0, 0, 0}
    }
    
    return _textView;
}

- (void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];

//    NSLog(@"%@",NSStringFromUIEdgeInsets(self.textView.contentInset));

}
//添加输入控件

- (void)setupTextView{
    //在控制器中textViewcontentInset.top默认会等于64
    [self.view addSubview:self.textView];
    
    
    
//    UITextField *textField;
//    addtarget监听
//    [textField addTarget:self action:@selector(<#selector#>) forControlEvents:UIControlEventTouchUpInside];
//      通知监听
//    [[NSNotificationCenter defaultCenter]addObserver:self forKeyPath:nil options:UITextFieldTextDidEndEditingNotification context:nil];
    
//        [[NSNotificationCenter defaultCenter]addObserver:self forKeyPath:nil options:UITextViewTextDidEndEditingNotification context:nil];

    
    
  }

//设置导航栏内容
- (void)setupNav{
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"取消" style:0 target:self action:@selector(cancel)];
    
    self.view.backgroundColor =[UIColor whiteColor];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"发送" style:0 target:self action:@selector(send)];
    self.navigationItem.rightBarButtonItem.enabled = NO;
    
    
    UILabel * titleView = [UILabel new];
    titleView.numberOfLines = 0;//自动换行
    titleView.y = 50;
    titleView.width = 200;
    titleView.height = 100;
    //    titleView.backgroundColor = [UIColor orangeColor];
    titleView.textAlignment = NSTextAlignmentCenter;
    
    NSString* name = [AccountTool account].name;
    NSString * prefix = @"发微博";
    NSString * str = [NSString stringWithFormat:@"%@\n%@",prefix,name];
    //创建一个带有属性的字符串 (颜色字体属性)
    NSMutableAttributedString* attrStr =  [[NSMutableAttributedString alloc]initWithString:str];
    //添加属性
    //    [attrStr addAttribute:NSFontAttributeName value:[UIFont boldSystemFontOfSize:13] range:[str rangeOfString:prefix]];
    
    [attrStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:12] range: [str rangeOfString:name]];
    [attrStr addAttribute:NSForegroundColorAttributeName value:[UIColor orangeColor] range: [str rangeOfString:name]];
    
    NSShadow * shadow = [[NSShadow alloc]init];
    shadow.shadowColor = [UIColor redColor];
    shadow.shadowBlurRadius = 10;
    shadow.shadowOffset = CGSizeMake(5, 5);
    //    [attrStr addAttribute:NSBackgroundColorAttributeName value:[UIColor purpleColor] range: [str rangeOfString:name]];
    
    
    //    NSTextAttachment * att = [[NSTextAttachment alloc]init];
    //    att.image = [UIImage imageNamed:@"vip"];
    //    NSAttributedString  * att2 =[NSAttributedString attributedStringWithAttachment:att];
    //    [attrStr appendAttributedString:att2];
    //    [attrStr appendAttributedString:[[NSAttributedString alloc] initWithString:@"哈哈"]];
    
    
    
    
    titleView.attributedText = attrStr;
    
    self.navigationItem.titleView = titleView;
    

    
}

- (void)cancel{
    
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (void)send{
    
}

@end
